package jp.co.cos.ittrick.channel.controller.client;

import jp.co.cos.ittrick.channel.model.TableModel;
import jp.co.cos.ittrick.channel.service.TableService;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

public class UpdateTableController extends Controller {

    private TableService tableService;

    public UpdateTableController() {
        tableService = new TableService();
    }

    @Override
    public Navigation run() throws Exception {

        // リクエストパラメータ
        String table = asString("table");
        String name = asString("name");

        // Modelの設定
        TableModel model = tableService.getTableByKey(Integer.valueOf(table));
        if(model != null) {
            model.setName(name);

            // Insert
            tableService.update(model);
        }

        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        response.getWriter().println("0");
        response.flushBuffer();

        return null;
    }
}
